$(function(){
	var ind = 1;
	var sidebarUlLeft = $(".sidebarUlLeft").find(".navlistchage");

	//sidebarUlLeft.click(function(){
	// 	updataImg($(this));
	//})
	
	function updataImg(_this){

		var _index = _this.index()+1;

		ind = _index;

		_this.removeClass("colorB");

		_this.children().removeClass("hreadChages");

		_this.siblings(".bhover").addClass("colorB");
		$(".contextRight"+_index).css("display","block").siblings(".contextMargin").css("display","none");
		_this.addClass("hreadChage").siblings().removeClass("hreadChage");
		
		var navImg = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon_hover"+_index+".png" : "Application/Home/Static/bt/img/bang_"+_index+".png";
		var navImg1 = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon1.png" : "Application/Home/Static/bt/img/bang1.png";
		var navImg2 = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon2.png" : "Application/Home/Static/bt/img/bang2.png";
		var navImg3 = ($(".sidebar-collapse").hasClass("chageMin")) ? "Application/Home/Static/bt/img/icon3.png" : "Application/Home/Static/bt/img/bang3.png";
		if(_index == 1){
			_this.children().children().attr("src",navImg);
			$(".class2").children().children().attr("src",navImg2);
			$(".class3").children().children().attr("src",navImg3);
			$(".leftArrow").css("top","15%");
			
		}else if(_index == 2){
			_this.children().children().attr("src",navImg);
			$(".class1").children().children().attr("src",navImg1);
			$(".class3").children().children().attr("src",navImg3);
			$(".leftArrow").css("top","48%");
			redirectPage();
			
		}else if(_index == 3){
			_this.children().children().attr("src",navImg);
			$(".class1").children().children().attr("src",navImg1);
			$(".class2").children().children().attr("src",navImg2);
			$(".leftArrow").css("top","83%");
		}
	}
	
	sidebarUlLeft.hover(function(){
		var _index = $(this).index()+1;
		sidebarUlLeftIn(_index,$(this));
	},function(){
		var _index = $(this).index()+1;
		sidebarUlLeftOut(_index,$(this));
	})
	
	function sidebarUlLeftIn(_index,_this){
		if(_this.hasClass("hreadChage")) return
		
		$(".sidebar-collapse").hasClass("chageMin") ? _this.children().children().attr("src","Application/Home/Static/bt/img/icon_hover"+_index+".png") : _this.children().children().attr("src","Application/Home/Static/bt/img/bang_"+_index+".png");
		
		_this.children().addClass("colorD hreadChages");
	}

	function sidebarUlLeftOut(_index,_this){
		if(_this.hasClass("hreadChage")) return
		
		$(".sidebar-collapse").hasClass("chageMin") ? _this.children().children().attr("src","Application/Home/Static/bt/img/icon"+_index+".png") : _this.children().children().attr("src","Application/Home/Static/bt/img/bang"+_index+".png");
		
		_this.children().removeClass("colorD hreadChages");
	}
	/*输入框的变色*/
	$("body").on("focus","input,textarea,select",function(){
		$(this).css("border","1px #354052 solid");
	})

	$("body").on("blur","input,textarea,select",function(){
		$(this).css("border","0px #354052 solid");
	})
	
	$(".listing").focus(function(){
		$(this).parent().siblings(".listingmsg").css("display","block")
	})

	$(".listing").blur(function(){
		$(this).parent().siblings(".listingmsg").css("display","none")
	})
	
	
	/*模态弹出框*/
	$(".resultBtn").click(function(){
		$(".modalAlert").show();
	});
	
	$(".close").click(function(){
		$(".modal").hide();
	})
	
	
	/*关键词分析自动生成数据*/
	function updataH(){
		var tab1Height = $(".btnmore").height();
		var keyH = $(".bgcolorMidK").height();
		if(tab1Height>=900){
			$(".bgcolorMid").css("height",tab1Height-170);
		}
	}
	updataH();

	$(".addBtn").click(function(){
		/*每一个table的数量不能超过40包括（40），超过40就自动生成一个table，以此类推*/
		var trLength = $(".ct_tableContainer:last-child").children("table").children("tbody").find("tr").length;
	
		if(trLength>120){
			/*整个table的数量*/
			var ct_length = $(".ct_tableContainer").length+1;
			var _html = " ";
			if(ct_length % 3 == 2){
				_html +='<div class="ct_tableContainer ct_table_padding">';
			}else{
				_html +='<div class="ct_tableContainer">';
			}
			_html +='<table class="ct_table">';
			_html +='<thead>';
			_html +='<tr class="tableStyle">';
			_html +='<th>aa</th><th>1</th><th>1%</th>';
			_html +='</tr>';
			_html +='</thead>';
			_html +='<tbody>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='<tr><td>aa</td><td>1</td><td>1%</td></tr>';
			_html +='</tbody>';
			_html +='</table>';
			_html +='</div>';
			
			$(".ct_context").append(_html);
		}
		updataH();
	})
	
	/*清空文本域的值*/
	$(".clearBtn").on("click",function(){
		$(".clearText").val(" ");
		$(".clearText").focus();
	})
	
	/*左边导航栏*/
	$(".sidebar-collapse").on("click",function(){
		if($(this).hasClass("chageMin")){
			$(this).removeClass("chageMin");
			$(".sidebar-toggle .ace-icon img").attr("src","Application/Home/Static/bt/img/lefts.png")
			$(".sidebarUlLeft li a img").css({"width":"91px","height":"90px"});
			$(".updataImg img").css({"width":"73px","height":"67px"});
			var imgout1 = (ind == 1) ? "Application/Home/Static/bt/img/bang_1.png" : "Application/Home/Static/bt/img/bang1.png";
			var imgout2 = (ind == 2) ? "Application/Home/Static/bt/img/bang_2.png" : "Application/Home/Static/bt/img/bang2.png";
			$(".class1").children().children().attr("src",imgout1);
			$(".class2").children().children().attr("src",imgout2);
			$(".class3").children().children().attr("src","Application/Home/Static/bt/img/bang3.png");
		}else{
			$(this).addClass("chageMin");
			$(".sidebar-toggle .ace-icon img").attr("src","Application/Home/Static/bt/img/rights.png")
			$(".sidebarUlLeft li a img").css({"width":"32px","height":"32px"});
			$(".updataImg img").css({"width":"43px","height":"39px"});
			var imgIn1 = (ind == 1) ? "Application/Home/Static/bt/img/icon_hover1.png" : "Application/Home/Static/bt/img/icon1.png";
			var imgIn2 = (ind == 2) ? "Application/Home/Static/bt/img/icon_hover2.png" : "Application/Home/Static/bt/img/icon2.png";
			$(".class1").children().children().attr("src",imgIn1);
			$(".class2").children().children().attr("src",imgIn2);
			$(".class3").children().children().attr("src","Application/Home/Static/bt/img/icon3.png");
		}
		
	})
	
	
	/*下拉框的选择功能*/
	var flayIndex = false;
	var menu = $(".delayed").find("li");
	menu.on("click",function(){
		$(".delayedInput").val($(this).children().html())
		flayIndex = true;
	})

	
	/*检测分辨率是否是小屏幕*/
	function redirectPage(){
		var screenWh = screen.width;
		if(screenWh <= 1366){
			//var navH = $(".navbar").css("height")+30;
			$('body,html').animate({ scrollTop: 200 }, 800);
		}
	}
	
	
	$(".checkGroup").on("click",function(){
		if($(this).children("i").hasClass("okBtn")){
			$(this).children("i").removeClass("okBtn glyphicon glyphicon-ok");
		}else{
			$(this).children("i").addClass("okBtn glyphicon glyphicon-ok");
		}
	})
	
	
	$(".radioContainer .radioGroup").on("click",function(){
		
		if($(this).children().children("i").hasClass("logo")){
			return;
		}
		if(!$(this).children().children("i").hasClass("radioLogo")){
			$(this).children().children("i").addClass("radioLogo logo");
			$(this).siblings().children().children().removeClass("radioLogo logo");
		}
	})
	
	
	/*提示框的效果*/
	$(".tooltipBtn").hover(function(){
		$(this).siblings(".tool").css("display","block");
	},function(){
		$(this).siblings(".tool").css("display","none");
	})
	
	function newDataTime(){
		var date = new Date();
		var Time = date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate();
			Time +=" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
			$(".Time").html("中国银行"+Time);
	}
	newDataTime();
	
	/*table切换功能*/
	var shoptable = $(".shopTable .shopNav").find("li");
	shoptable.on("click",function(){
		var _index = $(this).index()+1;
		$("div[class*=shoptable]").hide();
		$(".shoptable"+_index).show();
		$(this).addClass("active").siblings().removeClass("active");
	})
	
	var authorizetable = $(".authorizeTable .authorize-tabs").find("li");

	authorizetable.on("click",function(){
		var _index = $(this).index()+1;
		$("div[class*=shopAuthorize]").hide();
		$(".shopAuthorize"+_index).show();
		$(this).addClass("active").siblings().removeClass("active");
	})

	/**
	 * 账户设置  事件
	 */
	$(".setBtnClick").hover(function(){
		if(!$(this).hasClass("setbtn")){
			$(this).children("b").removeClass("fa-angle-down").addClass("fa-angle-up");
			$(this).addClass("setbtn");
			$(".setItme").fadeIn(200);
		}else{
			$(this).children("b").removeClass("fa-angle-up").addClass("fa-angle-down");
			$(this).removeClass("setbtn")
			$(".setItme").fadeOut(200);
		}
	})
	
	var setItme = $(".setItme ul").find("li");
	setItme.hover(function(){
		$(this).css({"background":"#00c18a","color":"#ffffff"});
	},function(){
		$(this).css({"background":"#FFFFFF","color":"#9ba7b9"});
	})

	/**
	 * 商品调价用户登录modal窗体
	 */
	$(".modalClick").on("click",function(){

		$("#shopModal").remove(); // 删除模态登录窗口

		var type = $(this).attr('clickType'); //登录 类型

		var miurl = "'/index.php?s=/ucenter/member/mi.html'"; // 忘记密码

		var registerurl = "'/index.php?s=/ucenter/member/register.html'"; //注册

		var _html = '<form action="/index.php?s=/ucenter/member/login.html" method="post" class="login-form">';
			_html +='<div class="modal fade" id="shopModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">';
			_html +='<div class="modal-dialog" role="document">';
			_html +='<div class="modal-content">';
			_html +='<div class="modal-header">';
			_html +='<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>';
			_html +='<h4 class="modal-title" id="myModalLabel">用户登录</h4>';
			_html +='</div>';
			_html +='<div class="modal-body">';
			_html +='<div class="modalMagrin">';
			_html +='<div class="modalMsg">此功能免费，但需与亚马逊数据同步，为了您的信息安全，请登录后使用</div>';
			_html +='<div class="modalDody">';

			_html +='<div class="userContainer ">';
			_html +='<input class="userStyle modalW user" type="text" name="username" placeholder="请输入邮箱"/>';
			_html +='<div class="modalLogo"><img src="Application/Home/Static/bt/img/user/user.png"/></div>';
			_html +='</div>';

			_html +='<div class="userContainer ">';
			_html +='<input class="userStyle modalW user" type="password" name="password" placeholder="请输入密码"/>';
			_html +='<div class="modalLogo modalPosition"><img src="Application/Home/Static/bt/img/user/userlogo.png"/></div>';
			_html +='</div>';

			_html +='<div class="userContainer" style="display: table;">';
			_html +='<div class="logoDisplay">';
			_html +='<input type="text" id="verifyCode" class="userStyle userCodeW" name="verify">';
			_html +='</div>';

			_html +='<div class="logoDisplay  userLogoW" >';
			_html +='<img class="verifyimg reloadverify indexVerifyimg" alt="点击切换" src="/index.php?s=/ucenter/member/verify.html" height="50"  style="cursor:pointer;max-width: 100%">';
			_html +='</div>'
			_html +='</div>';

			_html +='<div class="userContainer ">';
			_html +='<div class="userLogoBtn indexLand" style="color:#FFFFFF" clickLoginType="'+type+'">登录</div>';
			_html +='</div>';

			_html +='<div class="userContainer clearfix">';
			_html +='<div class="clearBtn size14 color9 ForgetPwd modalLeft" onclick="window.location.href='+miurl+'">忘记密码？</div>';
			_html +='<div class="modalStyle modalColor size14">';
			_html +='<span style="color:#666666">没有账户？</span>';
			_html +='<span class="modalColor" style="cursor: pointer;" onclick="window.location.href='+registerurl+'">立即注册</span>';
			_html +='</div></div>';

			_html +='<div class="userContainer loginUserContaine" style="display:none;">';
			_html +='<img style="vertical-align: sub;" class="loginColorRed" src="Application/Home/Static/bt/img/err_small_a1085c53.png">';
			_html +='<span class="size12 colorRed" style="margin-left: 7px;">输入错误</span>';
			_html +='<div>';
			_html +='</div></div></div></div></div></div>';
			_html+='</form>';
			$("body").append(_html);
	});

	$(".readjustClick").on("click",function(e){
		$(".readjustModal").remove();
		var _html = '';
		_html +='<div class="modal fade" id="readjustModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">';
		_html +='<div class="modal-dialog" role="document">';
		_html +='<div class="modal-content">';
		_html +='<div class="modal-header">';
		_html +='<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
		_html +='<h4 class="modal-title" id="myModalLabel">FBM库存批量调整</h4>';
		_html +='</div>';
		
		_html +='<div class="modal-body" style="padding: 30px 0 !important;">';
		_html +='<form class="form-horizontal" role="form" style="margin-left: 30px;">';
		_html +='<div class="form-group formmarginTop">';
		_html +='<label class="col-sm-2 col-xs-12 control-label no-padding-right labeichage shopright0">可售 <=</label>';
		_html +='<div class="col-sm-6 col-xs-10">';
		_html +='<input type="text" id="inputStyle" class="col-xs-10 col-sm-12 color3 tooltipBtn keyInput">';
		_html +='</div></div>';
		_html +='<div class="form-group formmarginTop">';
		_html +='<label class="col-sm-2 col-xs-12 control-label no-padding-right labeichage shopright0">全部调整为：</label>';
		_html +='<div class="col-sm-6 col-xs-10"><input type="text" id="inputStyle" class="col-xs-10 col-sm-12 color3 tooltipBtn keyInput"></div>';
		_html +='<div class="col-sm-4">';
		_html +='<div class="checkbox size14 ">';
		_html +='<div class="checkGroup position size14 ckBtn" onclick="ckBtn()">';
		_html +='<span class="color6 labeiLeft20">累加现在的可售数</span><i class="checkLogo"></i>';
		_html +='</div></div>';
		_html +='</div>';
		_html +='</div>';
		_html +='</form>';
		_html +='</div>';
		
		_html +='<div class="modal-footer">';
		_html +='<div class="updateBtnright modalFloat submitBtn" data-dismiss="modal">确定</div>';
		_html +='</div>';
		_html +='</div></div></div>';
		
		$("body").append(_html);
	})

	/**
	 * 账户设置
	 */
	$(".userManageClick").on("click",function(){
		var imgarry = ["Application/Home/Static/bt/img/bang1.png","Application/Home/Static/bt/img/bang2.png","Application/Home/Static/bt/img/bang3.png"];
		var _index = $(this).attr("data-index");
		var side = $(".sidebarUlLeft").find("li");
		var sum = 0;
		for(var i=0,len=side.length;i<len;i++){
			sum = i+1;
			side.addClass("colorB").removeClass("hreadChage");
			$(".class"+sum).children().children().attr("src",imgarry[i]);
		};

		switch(_index){
			case '6':
				window.location.href  = '/index.php?s=/home/index/amazonauthmarkest';
				break;
			case '5':
				window.location.href = '/index.php?s=/home/index/accountAdministration';
				break;
			case '4':
				window.location.href = '/index.php?s=/home/index/expandinfo';
				break;
		}

	})
	
	/*授权table切换复选框效果*/
	$(".authorizeBtnClick").on("click",function(){
		var _html = "";
		var name = $(this).children("span").text();
		var authorizeIndex =$(".authorizeTable").children().children(".active").attr("data-cty");
		
		var _index = $(this).attr("data-tab");
		if(!$(this).children("i").hasClass("okBtn")){
			$(".removeIndex"+_index).remove();
			return;
		}
		_html +='<div class="col-xs-12 shopleft0 shopright0 marginBottom20 removeInputDiv removeIndex'+_index+'">';
		_html +='<label class="col-xs-2 shopleft0 shopright0 labeiTop6">店铺名称：</label>';
		_html +='<input id="inputStyle" class="col-xs-10 UserMarketCNName" type="text" placeholder="请输入'+name+'店铺名称" />';
		_html +='<input class="MarketID" type="hidden" value="'+_index+'"/>';
		_html +='</div>';
		
		$(".shopAuthorize"+authorizeIndex).append(_html);
	})
	
	$(".timeInputxs").focus(function(){
		$(".borderLeft").css("border-left","1px #000000 solid")
	});

	$(".timeInputxs").blur(function(){
		$(".borderLeft").css("border-left","0px #000000 solid")
	});

	/*商品调价保存按钮*/
	$("#productList").on('keyup','.producPrice',function(){
		var value = $(this).val().replace(/[^\d+.]/g,'');
		$(this).val(value);
		$(this).siblings(".savalogo").show();
	});

	/*用户注册导航栏功能*/
	var logoNav = $(".logoNavRight").find("a");
	logoNav.hover(function(){
		$(this).addClass("active");
	},function(){
		$(this).removeClass("active");
	});

	/*未登录用户弹出的media  Input边框*/
	$(document).on("focus","input[class~=userBorder]",function(){
		$(this).css("border","1px #354052 solid");
	});

	$(document).on("blur","input[class~=userBorder]",function(){
		$(this).css("border","0px #354052 solid");
	});


	$(document).bind('click', function(e) {
	  var e = e || window.event; //浏览器兼容性
	  var elem = e.target || e.srcElement;
	  while (elem) {
	    //循环判断至跟节点，防止点击的是div子元素
	    if (elem.id && elem.id == 'menu') {
	      return;
	    }
	    elem = elem.parentNode;
	  }
	  //点击的不是div或其子元素
		 if($(".inputMenu").hasClass("open")){
		 	 $(".inputMenu").removeClass("open");
		 }
		 
	});

/***************************************************xiaojing add code***********************************************************/

	/**
	 * 用户 退出
	 * @author xiaojing
	 */
	$('#logout').on('click',function(){
		var url =  $(this).attr('href');
		$.post(url,{},function(res){
			window.location.href = res.url;
		},'JSON');
		return false;
	});

	/**
	 * 模态窗 登陆 操作
	 * @author xiaojing
	 */
	$('body').on('click','.indexLand',function(){
		var self = $(this).parents('form');
		var loginType = $(this).attr('clickLoginType');
		$(this).find('.loginUserContaine').hide();
		$.post(self.attr("action"), self.serialize(), function(res){
			if(res.status){
				switch(loginType)
				{
				case 'product':
					window.location.href = '/index.php?s=/home/index/product';
					break;
				default:
					window.location.reload();
					//window.location.href = res.url;
				}
			}else{
				$('.colorRed').text(res.info);
				$('.colorRed').parent().show();
				//登陆不成功动态更换验证码
				$('.indexVerifyimg').attr('src','index.php?s=/ucenter/member/verify.html');
			}
		}, "json");
	});

	/**
	 * 点击  模态窗 验证码
	 * @author xiaojing
	 */
	$('body').on('click','.indexVerifyimg',function(){
		$(this).attr('src','index.php?s=/ucenter/member/verify.html');
	});

	/**
	 * 修改 密码 模态 窗口
	 * @author xiaojing
	 */
	$(".retrievePassword").on("click",function(){

		$("#retrievePasswordModal").remove();

		var _html = '<form action="/index.php?s=/ucenter/member/profile" method="post" class="login-form">';
					_html +='<div class="modal fade" role="dialog" id="retrievePasswordModal" aria-labelledby="gridSystemModalLabel">';
					_html +='<div class="modal-dialog" role="document">';
					_html +='<div class="modal-content">';
					_html +='<div class="modal-header">';
					_html +='<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>';
					_html +='<h4 class="modal-title" id="myModalLabel">修改密码</h4>';
					_html +='</div>';
					_html +='<div class="modal-body">';
					_html +='<div class="modalMagrin">';
					_html +='<div class="modalMsg"></div>';
					_html +='<div class="modalDody">';

					_html +='<div class="userContainer">';
					_html +='<input class="userStyle modalW user" type="password" name="old" placeholder="请输入旧密码"/>';
					_html +='<div class="modalLogo"><img src="Application/Home/Static/bt/img/user/userlogo.png"/></div>';
					_html +='</div>';

					_html +='<div class="userContainer">';
					_html +='<input class="userStyle modalW user" type="password" name="password" placeholder="请输入新密码"/>';
					_html +='<div class="modalLogo"><img src="Application/Home/Static/bt/img/user/userlogo.png"/></div>';
					_html +='</div>';

					_html +='<div class="userContainer ">';
					_html +='<input class="userStyle modalW user" type="password" name="repassword" placeholder="确认新密码"/>';
					_html +='<div class="modalLogo"><img src="Application/Home/Static/bt/img/user/userlogo.png"/></div>';
					_html +='</div>';

					_html +='<div class="userContainer ">';
					_html +='<div class="userLogoBtn indexRetrievePassword" style="color:#FFFFFF">保存</div>';
					_html +='</div>';

					_html +='<div class="userContainer loginUserContaine" style="display:none;">';
					_html +='<img style="vertical-align: sub;" class="loginColorRed" src="Application/Home/Static/bt/img/err_small_a1085c53.png">';
					_html +='<span class="size12 colorRed" style="margin-left: 7px;">输入错误</span>';
					_html +='<div>';

					_html +='</div></div></div></div></div></div>';
					_html+='</form>'
		$("body").append(_html);
	});

	/**
	 * 模态窗 找回密码 操作
	 * @author xiaojing
	 */
	$('body').on('click','.indexRetrievePassword',function(){

		var self = $(this).parents('form');

		$(this).find('.loginUserContaine').hide();

		var inputPassword  = self.find('#password').val();

		var inputPassword2 = self.find('#repassword').val();

		if(inputPassword != inputPassword2){
			$('.colorRed').text('两次输入的密码不一样~！').parent().show();
			return false;
		}
		$.post(self.attr("action"), self.serialize(), function(res){
			if(res.status){
				window.location.href = res.url;
			}else{
				if(data.info == -4){
					$('.colorRed').text('密码不能少于6个字符').parent().show();
					return false;
				}
				$('.colorRed').text(res.info).parent().show();
			}
		}, "json");
	});
	
});
